import { createSlice, PayloadAction } from '@reduxjs/toolkit'

export interface userType {
  user_info: IUserInfo
  is_menu_collapsed: boolean
}

export interface IUserInfo {
  address?: string
  email?: string
  id?: string
  id_card?: string
  name?: string
  phone?: string
  sex?: number
}

const initialState: userType = {
  user_info: {},
  is_menu_collapsed: false,
}
export const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    changeUserInfoAction(state, action: PayloadAction<IUserInfo>) {
      state.user_info = action.payload
    },
    changeMenuCollapsed(state, action: PayloadAction<boolean>) {
      state.is_menu_collapsed = action.payload
    },
  },
})
export const { changeUserInfoAction, changeMenuCollapsed } = userSlice.actions
export default userSlice.reducer
